package com.atguigu.gmall;

import com.atguigu.gmall.model.product.SkuInfo;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;

/**
 * @author: 李旭
 * @create: 2021-07-10 10:06
 **/
//@RunWith(SpringJUnit4ClassRunner.class)
//@RunWith(SpringRunner.class)
//@SpringBootTest(classes = ServiceProductApplication.class)
public class RedisDemo {

    @Autowired
    private RedisTemplate redisTemplate;//默认的配置

   @Test
    public void test1() throws Exception{

 /*      SkuInfo skuInfo = new SkuInfo();//对象
       redisTemplate.opsForValue().set("K",skuInfo);//aXsfdasdfas K    V： json格式的字符串

       redisTemplate.opsForValue().get("K");*/


       redisTemplate.opsForValue().set("K","V");
       // K  :  V
       redisTemplate.opsForHash().put("h","hk","hv");
       //Map h = new HashMap();
       //h.put(hk,hv)




       ObjectMapper objectMapper = new ObjectMapper();



       //@ResponseBody
       SkuInfo skuInfo = new SkuInfo();
       skuInfo.setIsSale(111);

       String json = objectMapper.writeValueAsString(skuInfo);
       System.out.println(json);
       //{"id":null,"spuId":null,"price":null,"skuName":null,"skuDesc":null,"weight":null,"tmId":null,"category3Id":null,"skuDefaultImg":null,"isSale":111,"skuImageList":null,"skuAttrValueList":null,"skuSaleAttrValueList":null}
       //@RequestBody
       SkuInfo skuInfo1 = objectMapper.readValue(json, SkuInfo.class);
       System.out.println(skuInfo1);
   }
}
